package com.a3dweijing.wetouch2.adapter;

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.Util.ImageLoaderUtil;
import com.a3dweijing.wetouch2.bean.Special;
import com.a3dweijing.wetouch2.callback.OnClick;

import java.util.Collections;
import java.util.List;

/**
 * Created by Yxd on 2017/11/14.
 */

public class SpecialBottomRecAdapter extends RecyclerView.Adapter<SpecialBottomRecAdapter.MyViewHolder> {
    private List<Special> specials;
    private OnClick onClick;

    public void setOnClick(OnClick onClick) {
        this.onClick = onClick;
    }

    public SpecialBottomRecAdapter(List<Special> specials) {
        Collections.sort(specials);
        this.specials = specials;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_special_bottom,parent,false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onClick!=null)
                    onClick.onclick(position,specials.get(position));
            }
        });
        ImageLoaderUtil.getLoader().loadImg2(specials.get(position).getSpecial_topic_img(),holder.pic);
        holder.name.setText(specials.get(position).getSpecialtopic_headline());
        holder.content.setText(specials.get(position).getSpecial_topic_describe());
    }

    @Override
    public int getItemCount() {
        return specials.size();
    }

    class MyViewHolder extends ViewHolder {
        ImageView pic;
        TextView name;
        TextView content;
        TextView updata;
        public MyViewHolder(View itemView) {
            super(itemView);
            pic= (ImageView) itemView.findViewById(R.id.special_item_pic);
            name= (TextView) itemView.findViewById(R.id.special_item_name);
            content= (TextView) itemView.findViewById(R.id.special_item_content);
            updata= (TextView) itemView.findViewById(R.id.special_item_updata);
        }
    }
}
